import scrapy
from shopSpider.items import GoodsListItem
import json

class GoodsListSpider(scrapy.Spider):
    name = "goodsList"
    allowed_domains = ["api-gw.onebound.cn"]
    secret = '23883da6' 
    key = 't9911312388'   
    shop_id = '118417502'
    seller_id = '2453725193'
    shop_name = '高露洁诺晶专卖店'
    start_urls = ["https://api-gw.onebound.cn/taobao/item_search_shop/?key={}&&shop_id={}&seller_id={}&page=1&sort=sale&&lang=zh-CN&secret={}&sort=sale".format(key,shop_id,seller_id,secret)]

    def parse(self, response):
        data = json.loads(response.text)
        for goodsItem in data['items']['item']:
            item = GoodsListItem()
            item['title'] = goodsItem['title']
            item['num_iid'] = goodsItem['num_iid']
            item['promotion_price'] = goodsItem['promotion_price']
            item['price'] = goodsItem['price']
            item['shop_id'] = goodsItem['shop_id']
            item['shop_name'] = self.shop_name
            item['sales'] = goodsItem['sales']
            item['seller_id']= goodsItem['seller_id']
            item['pic_url']= goodsItem['pic_url']
            item['detail_url']= goodsItem['detail_url']
            yield item

